//
//  YHModuleTwoViewController_2.m
//  YHRouter_Example
//
//  Created by 98du on 2021/11/26.
//  Copyright © 2021 林宁宁. All rights reserved.
//

#import "YHModuleTwoViewController_2.h"
#import "YHModuleTwoService.h"

@import YHRouter;
@interface YHModuleTwoViewController_2 ()

@property (copy, nonatomic) NSString * type;
@property (copy, nonatomic) NSString * name;
@property (assign, nonatomic) NSInteger index;

@end

@implementation YHModuleTwoViewController_2

+(void)load{
    [YHRouter yh_bindKey:kYHModuleTwoViewController_2 vcClass:self toHandler:^id _Nullable(NSDictionary * _Nullable parameters) {
        return [YHModuleTwoViewController_2 new];
    }];
}

-(void)yh_routerPassParams:(YHRouterParam *)parameters{
    self.type = parameters.arg1;
    self.name = parameters.arg2;
    self.index = parameters.arg3?[parameters.arg3 intValue]:0;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UILabel * labelParam = [UILabel new];
    labelParam.textAlignment = NSTextAlignmentCenter;
    labelParam.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.2];
    labelParam.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 300);
    labelParam.font = [UIFont boldSystemFontOfSize:20];
    labelParam.numberOfLines = 0;
    [self.view addSubview:labelParam];
    labelParam.text = [NSString stringWithFormat:@"type : %@\n name : %@\n index : %ld\n",self.type,self.name,self.index];
 
    if(self.index == 100){
        return;
    }
    
    UIButton * btnCallBack = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [btnCallBack setTitle:@"回调数据回去" forState:(UIControlStateNormal)];
    [btnCallBack addTarget:self action:@selector(callBackEvent) forControlEvents:(UIControlEventTouchUpInside)];
    btnCallBack.frame = CGRectMake(0, 320, CGRectGetWidth(self.view.frame), 44);
    [self.view addSubview:btnCallBack];
}

- (void)callBackEvent{
    if(self.yh_callback){
        self.yh_callback([YHRouterParam params:@"我回来了", nil]);
    }
    self.yh_pop();
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
